﻿using System;
using System.Collections.Generic;
using System.Collections;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admin_JobPosition_Employement : System.Web.UI.Page
{
    public ArrayList jobpositionarr = null;
    public int id = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["user"] == null) { Response.Redirect("../Index.aspx"); }
        
        jobpositionarr = (ArrayList)DB.getArrTipoContrato("");
        if (!Page.IsPostBack)
        {
            llenocompanias();

            if (Request.QueryString["id"] != null) id = int.Parse(Request.QueryString["id"].ToString());

            lb_employeeid.Text = id.ToString();

            RE_GenericBean employement = DB.getTipoContrato(id);

            lb_employeeid.Text = employement.intC1.ToString();
            ddl_companyid.SelectedValue = employement.intC2.ToString();
            tb_employementtype.Text = employement.strC1;
            tb_employementdesc.Text = employement.strC2;
            if (employement.intC1 != 0)
            {
                habilitocampos(false);
                HyperLink1_ModalPopupExtender.Show();
            }
        } else {
            id = int.Parse(lb_employeeid.Text);
        }

    }    

    private void habilitocampos(bool estado)
    {
        tb_employementtype.Enabled = estado;
        tb_employementdesc.Enabled = estado;
        ddl_companyid.Enabled = estado;
    }

    private void llenocompanias()
    {
        ArrayList companyarr = null;
        ListItem item = null;
        try
        {
            companyarr = (ArrayList)DB.getArrCompania("");
            if (companyarr != null && companyarr.Count > 0)
            {
                foreach (RE_GenericBean company in companyarr)
                {
                    item = new ListItem(company.strC1, company.intC1.ToString());
                    ddl_companyid.Items.Add(item);
                }
            }
        }
        catch (Exception err)
        {
            utility.log(err.StackTrace);
        }
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        bool actualiza = false;

        RE_GenericBean jobposition = new RE_GenericBean();
        jobposition.intC1 = int.Parse(lb_employeeid.Text.Trim());
        jobposition.intC2 = int.Parse(ddl_companyid.SelectedValue);
        jobposition.strC1 = tb_employementtype.Text.Trim().ToUpper();
        jobposition.strC2 = tb_employementdesc.Text.Trim();

        if (jobposition.intC1 != 0) actualiza = true;

        if (DB.InsertTypeJob(jobposition, actualiza))
        {
            habilitocampos(false);
            Response.Redirect("JobPosition_Employement.aspx");
        }
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        habilitocampos(true);
        HyperLink1_ModalPopupExtender.Show();
    }
    protected void LinkButton3_Click(object sender, EventArgs e)
    {
        int id = 0;
        id = int.Parse(lb_employeeid.Text);
        if (id != 0)
        {
            int result = DB.DeleteJobEmployement(id);
            Response.Redirect("JobPosition_Employement.aspx");
        }
    }
}